﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Data;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using Microsoft.Maps.MapControl;
using System.Text.RegularExpressions;
using System.Threading;
using System.Collections;
using System.Collections.ObjectModel;

using SL4_NAV_ProjectiCON.Model;
using SL4_NAV_ProjectiCON.Providers;

namespace SL4_NAV_ProjectiCON.Views
{
    public partial class MnRApproval : Page
    {
        int PageNumber = 0;
        int PageIndex = 7;
        private Random _random = new Random();
        //IEnumerable _lookup;
        //ObservableCollection<SL4_NAV_ProjectiCON.DataService.DataTableInfo> _tables;
        List<DataGridRow> Rows = new List<DataGridRow>();
       
        public MnRApproval()
        {
            InitializeComponent();
            dataGrid1.LoadingRow += (sender, e) =>
            {
                var oldRows = Rows.Where(w => w.DataContext.Equals(e.Row.DataContext)).ToList();
                foreach (var row in oldRows)
                {
                    Rows.Remove(row);
                }
                Rows.Add(e.Row);
            };
        }

        public bool IsWorking
        {
            get { return myProgressbar.IsIndeterminate; }
            set { myProgressbar.IsIndeterminate = value; }

        }

      private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
           
            int busyDisplay = 3;
            int delayDisplay = 500;
            BusyWindow.DisplayAfter = TimeSpan.FromMilliseconds(delayDisplay);
            BusyWindow.IsBusy = true;
            ThreadPool.QueueUserWorkItem((state) =>
            {
                Thread.Sleep(busyDisplay * 1000);
                Dispatcher.BeginInvoke(() => BusyWindow.IsBusy = false);
            });

            Clear();
            SL4_NAV_ProjectiCON.DataService.DataServiceClient objCust = new SL4_NAV_ProjectiCON.DataService.DataServiceClient();
            objCust.GetCustomersCompleted += new EventHandler<SL4_NAV_ProjectiCON.DataService.GetCustomersCompletedEventArgs>(GetCustomersCompleted);
            objCust.GetCustomersAsync();  
            //objCust.GetDataSetDataCompleted  += new EventHandler<SL4_NAV_ProjectiCON.DataService.GetDataSetDataCompletedEventArgs>(ws_GetDataSetDataCompleted);
            //objCust.GetDataSetDataAsync("", 1, 25); 
           
            // create a PageCollection view from our sales data 
            //PagedCollectionView collectionView = new PagedCollectionView(dataGrid1.ItemsSource);
            //// set the page size 
            //collectionView.PageSize = 10;
            //// set the data context to the page collection views 
            //dgCustomerPager.DataContext = collectionView;
        }

      public void Load(String objCuststr)
        {

            int busyDisplay = 3;
            int delayDisplay = 500;
            BusyWindow.DisplayAfter = TimeSpan.FromMilliseconds(delayDisplay);
            BusyWindow.IsBusy = true;
            ThreadPool.QueueUserWorkItem((state) =>
            {
                Thread.Sleep(busyDisplay * 1000);
                Dispatcher.BeginInvoke(() => BusyWindow.IsBusy = false);
            });
            Clear();
            SL4_NAV_ProjectiCON.DataService.DataServiceClient objCust = new SL4_NAV_ProjectiCON.DataService.DataServiceClient();
            objCust.GetCustomersCompleted += new EventHandler<SL4_NAV_ProjectiCON.DataService.GetCustomersCompletedEventArgs>(GetCustomersCompleted);
            //objCust.GetCustomersAsync();
            objCust.GetDataSetDataAsync(objCuststr,1,25); 

        }

        public void ReLoad(String objCuststr)
        {
            int busyDisplay = 3;
            int delayDisplay = 500;
            BusyWindow.DisplayAfter = TimeSpan.FromMilliseconds(delayDisplay);
            BusyWindow.IsBusy = true;
            ThreadPool.QueueUserWorkItem((state) =>
            {
                Thread.Sleep(busyDisplay * 1000);
                Dispatcher.BeginInvoke(() => BusyWindow.IsBusy = false);
            });
            Clear();
            SL4_NAV_ProjectiCON.DataService.DataServiceClient objCust1 = new SL4_NAV_ProjectiCON.DataService.DataServiceClient();
            objCust1.GetCustomersBynameCompleted += new EventHandler<SL4_NAV_ProjectiCON.DataService.GetCustomersBynameCompletedEventArgs>(GetCustomersByNameCompleted);
            objCust1.GetCustomersBynameAsync(objCuststr);
           
        }

        // PROCESS PICTURE INFO --STARTS HERE

        private void ImagesListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
           // MouseLeaveStoryboard.Begin();
        }

        private void MouseLeaveStoryboard_Completed(object sender, EventArgs e)
        {
           // MouseEnterStoryboard.Begin();
        }

        private void LeftArrowButton_Click(object sender, RoutedEventArgs e)
        {
            if (PageNumber > 0)
            {
                PageNumber = PageNumber - 1;
                
                SL4_NAV_ProjectiCON.DataService.DataServiceClient objImg = new SL4_NAV_ProjectiCON.DataService.DataServiceClient();
                objImg.GetImageListCompleted += new EventHandler<SL4_NAV_ProjectiCON.DataService.GetImageListCompletedEventArgs>(objImg_GetImageListCompleted);
                objImg.GetImageListAsync();
            }
        }

        private void RightArrowButton_Click(object sender, RoutedEventArgs e)
        {

            PageNumber = PageNumber + 1;
            SL4_NAV_ProjectiCON.DataService.DataServiceClient objImg = new SL4_NAV_ProjectiCON.DataService.DataServiceClient();
            objImg.GetImageListCompleted += new EventHandler<SL4_NAV_ProjectiCON.DataService.GetImageListCompletedEventArgs>(objImg_GetImageListCompleted);
            objImg.GetImageListAsync();

        }

        void objImg_GetImageListCompleted(object sender, SL4_NAV_ProjectiCON.DataService.GetImageListCompletedEventArgs e)
        {
            ImagesListBox.ItemsSource = e.Result.Skip((PageNumber) * PageIndex).Take(7);
            //ImagesListBox.ItemsSource = e.Result.Skip(PageNumber).Take(7);
            ImagesListBox.SelectedIndex = 0;
        }
        // PROCESS PICTURE INFO --ends HERE

        // CONTAINER INFO -- STARTS HERE
        void GetCustomersCompleted(object sender, SL4_NAV_ProjectiCON.DataService.GetCustomersCompletedEventArgs e)
        {
            //MapLayer PushPinLayer = null;
            //PushPinLayer = new MapLayer();
            //PushPinLayer.Name = "PushPinLayer";
           // MyMap.Children.Add(PushPinLayer);
            dataGrid1.ItemsSource = e.Result;
             
           // dataGrid1.ItemsSource = DynamicDataBuilder.GetDataList(e.Result); 


            //PagedCollectionView collectionView = new PagedCollectionView(e.Result);
            //// set the page size 
            //collectionView.PageSize = 10;
            //// set the data context to the page collection views 
            //this.DataContext = collectionView;

            dataGrid1.SelectionChanged += new SelectionChangedEventHandler(dataGrid1_SelectionChanged);
            foreach (SL4_NAV_ProjectiCON.DataService.Customer C in e.Result)
            {
                CustomerPushpin pin;
                Location d = new Location(Convert.ToDouble(C.Latitude), Convert.ToDouble(C.Longitude));
                if (C.CustomerId > 10050)
                    pin = new CustomerPushpin(Colors.Blue);
                else
                    pin = new CustomerPushpin(Colors.Red);

                pin.Location = d;
                pin.Name = C.CustomerId.ToString();
                pin.CustomerId = C.CustomerId.ToString();
                pin.CustomerName = C.CustomerName.ToString();
                ScaleTransform st = new ScaleTransform();
                st.ScaleX = 0.25;
                st.ScaleY = 0.25;
                st.CenterX = (pin as FrameworkElement).Height / 2;
                st.CenterY = (pin as FrameworkElement).Height / 2;

                pin.RenderTransform = st;
                pin.MouseEnter += new MouseEventHandler(point_MouseEnter);
                pin.MouseLeave += new MouseEventHandler(point_MouseLeave);
                PushPinLayer.AddChild(pin, d);
            }
        }

        //void ws_GetDataSetDataCompleted(object sender, SL4_NAV_ProjectiCON.DataService.GetDataSetDataCompletedEventArgs e)
        //{

        //    dataGrid1.ItemsSource = DynamicDataBuilder.GetDataList(e.Result);

        //}
        //    //PagedCollectionView collectionView = new PagedCollectionView(e.Result);
        //    //// set the page size 
        //    //collectionView.PageSize = 10;
        //    //// set the data context to the page collection views 
        //    //this.DataContext = collectionView;

        //    //dataGrid1.SelectionChanged += new SelectionChangedEventHandler(dataGrid1_SelectionChanged);
        //    //foreach (SL4_NAV_ProjectiCON.DataService.DataSetData  C in e.Result)
        //    //{
        //    //    CustomerPushpin pin;
        //    //    Location d = new Location(Convert.ToDouble(C.Latitude), Convert.ToDouble(C.Longitude));
        //    //    if (C.CustomerId > 10050)
        //    //        pin = new CustomerPushpin(Colors.Blue);
        //    //    else
        //    //        pin = new CustomerPushpin(Colors.Red);

        //    //    pin.Location = d;
        //    //    pin.Name = C.CustomerId.ToString();
        //    //    pin.CustomerId = C.CustomerId.ToString();
        //    //    pin.CustomerName = C.CustomerName.ToString();
        //    //    ScaleTransform st = new ScaleTransform();
        //    //    st.ScaleX = 0.25;
        //    //    st.ScaleY = 0.25;
        //    //    st.CenterX = (pin as FrameworkElement).Height / 2;
        //    //    st.CenterY = (pin as FrameworkElement).Height / 2;

        //    //    pin.RenderTransform = st;
        //    //    pin.MouseEnter += new MouseEventHandler(point_MouseEnter);
        //    //    pin.MouseLeave += new MouseEventHandler(point_MouseLeave);
        //    //    PushPinLayer.AddChild(pin, d);
        //    //}
      
       
        void GetCustomersByNameCompleted(object sender, SL4_NAV_ProjectiCON.DataService.GetCustomersBynameCompletedEventArgs e)
        {
            dataGrid1.ItemsSource = e.Result;

        }

        public void Clear()
        {
            List<UIElement> elementsToRemove = new List<UIElement>();
            List<UIElement> pushpinToRemove = new List<UIElement>();
            foreach (UIElement element in MyMap.Children)
            {
                if (element.GetType() == typeof(MapLayer))
                {
                    MapLayer Lay = (MapLayer)element;
                    if (Lay.Name == "PushPinLayer")
                    {
                        foreach (UIElement p in Lay.Children)
                        {
                            if (p.GetType() == typeof(CustomerPushpin))
                            {
                                pushpinToRemove.Add(p);
                            }
                        }
                        foreach (UIElement pin in pushpinToRemove)
                        {
                            Lay.Children.Remove(pin);
                        }
                    }
                    elementsToRemove.Add(Lay);
                }
            }
            //foreach (UIElement e in elementsToRemove)
            //{
            //    MyMap.Children.Remove(e);
            //}
        }

        private void LoadButton_Click(object sender, RoutedEventArgs e)
        {
            Load("");
        }

        private void ClearButton_Click(object sender, RoutedEventArgs e)
        {
            Clear();
        }


        void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //to get the current row binding value
           
            //SL4_NAV_ProjectiCON.DataService.Customer currentRow = (SL4_NAV_ProjectiCON.DataService.Customer)dataGrid1.SelectedItem;
            SL4_NAV_ProjectiCON.DataService.Customer currentRow = (SL4_NAV_ProjectiCON.DataService.Customer)dataGrid1.SelectedItem;
           // SL4_NAV_ProjectiCON.DataService.DataSetData currentRow1 = (SL4_NAV_ProjectiCON.DataService.DataSetData)dataGrid1.SelectedItem;
            ////to read the currentRow
            string CustomerName = currentRow.CustomerName;

            int busyDisplay = 3;
            int delayDisplay = 100;
            BusyWindow1.DisplayAfter = TimeSpan.FromMilliseconds(delayDisplay);
            BusyWindow1.IsBusy = true;
            ThreadPool.QueueUserWorkItem((state) =>
            {
                Thread.Sleep(busyDisplay * 1000);
                Dispatcher.BeginInvoke(() => BusyWindow1.IsBusy = false);
            });

            ProcessEstimates(CustomerName);

            SL4_NAV_ProjectiCON.DataService.DataServiceClient objImg = new SL4_NAV_ProjectiCON.DataService.DataServiceClient();
            objImg.GetImageListCompleted += new EventHandler<SL4_NAV_ProjectiCON.DataService.GetImageListCompletedEventArgs>(objImg_GetImageListCompleted);
            objImg.GetImageListAsync();

        }

        void ProcessEstimates(string containerName)
        {
            
            ObservableCollection<Westimdt> lst_westimdt;
            lst_westimdt = WestimdtProviders.GetWestimDtDetails();
            ClearContent();
            if (containerName == "CRXU8970980")
            {
                containerName = "CMUG543216";
               

                foreach (var it in lst_westimdt)
                {
                    if (this.RB1N.Content.ToString() == it.WD_LOCATION)
                    {
                        //MessageBox.Show(it.WD_LINE);
                        //MessageBox.Show(it.WD_LOCATION);
                        //MessageBox.Show(this.RB4N.Content.ToString());
                        Border border = new Border();
                        border.Width = 60;
                        border.Height = 60;
                        border.Background = new SolidColorBrush(Color.FromArgb(255, (byte)_random.Next(255), (byte)_random.Next(255), (byte)_random.Next(255)));
                        RB1N.Content = border;

                    }

                    if (this.UX1N.Content.ToString() == it.WD_LOCATION)
                    {
                        Border border = new Border();
                        border.Width = 60;
                        border.Height = 60;
                        border.Background = new SolidColorBrush(Color.FromArgb(255, (byte)_random.Next(255), (byte)_random.Next(255), (byte)_random.Next(255)));
                        UX1N.Content = border;
                        //TR2N.Content= "PANEL, PATCH,";
                        //output.Text = "UNDERSTRUCTURE PANEL- DAMAGE : SCRATCHES, REPAIR- WASHING & CLEANING";
                    }

                    if (this.RB4N.Content.ToString() == "RB4N")
                    {

                        //TR2N.Content= "PANEL, PATCH,";
                        // output.Text = "PANEL - DAMAGE : DENT , REPAIR- STRAIGHTEN";
                    }
                    if (this.RH1N.Content.ToString() == "RH1N")
                    {
                        Border border = new Border();
                        border.Width = 60;
                        border.Height = 60;
                        border.Background = new SolidColorBrush(Color.FromArgb(255, (byte)_random.Next(255), (byte)_random.Next(255), (byte)_random.Next(255)));
                        RH1N.Content = border;
                        //TR2N.Content= "PANEL, PATCH,";
                        //output.Text = "CROSS MEMBER - DAMAGE : PATCH , REPAIR- REPLACE";
                    }

                    if (this.DB4N.Content.ToString() == "DB4N")
                    {
                        Border border = new Border();
                        border.Width = 60;
                        border.Height = 60;
                        border.Background = new SolidColorBrush(Color.FromArgb(255, (byte)_random.Next(255), (byte)_random.Next(255), (byte)_random.Next(255)));
                        DB4N.Content = border;
                        //TR2N.Content= "PANEL, PATCH,";
                        //output.Text = "DOOR PANEL - DAMAGE : DENT , REPAIR- STRAIGHTEN";
                    }
                }
            }
            if (containerName == "CRSY9898900")
            {
                containerName = "CRXU123456";

                foreach (var it in lst_westimdt)
                {
                    if (this.RB4N.Content.ToString() == it.WD_LOCATION)
                    {
                        //MessageBox.Show(it.WD_LINE);
                        //MessageBox.Show(it.WD_LOCATION);
                        //MessageBox.Show(this.RB4N.Content.ToString());
                        Border border = new Border();
                        border.Width = 60;
                        border.Height = 60;
                        border.Background = new SolidColorBrush(Color.FromArgb(255, (byte)_random.Next(255), (byte)_random.Next(255), (byte)_random.Next(255)));
                        RB4N.Content = border;

                    }

                    if (this.UX3N.Content.ToString() == it.WD_LOCATION)
                    {
                        Border border = new Border();
                        border.Width = 60;
                        border.Height = 60;
                        border.Background = new SolidColorBrush(Color.FromArgb(255, (byte)_random.Next(255), (byte)_random.Next(255), (byte)_random.Next(255)));
                        UX3N.Content = border;
                        //TR2N.Content= "PANEL, PATCH,";
                        //output.Text = "UNDERSTRUCTURE PANEL- DAMAGE : SCRATCHES, REPAIR- WASHING & CLEANING";
                    }

                    if (this.RB4N.Content.ToString() == "RB4N")
                    {

                        //TR2N.Content= "PANEL, PATCH,";
                        // output.Text = "PANEL - DAMAGE : DENT , REPAIR- STRAIGHTEN";
                    }
                    if (this.RH5N.Content.ToString() == "RH5N")
                    {
                        Border border = new Border();
                        border.Width = 60;
                        border.Height = 60;
                        border.Background = new SolidColorBrush(Color.FromArgb(255, (byte)_random.Next(255), (byte)_random.Next(255), (byte)_random.Next(255)));
                        RH5N.Content = border;
                        //TR2N.Content= "PANEL, PATCH,";
                        //output.Text = "CROSS MEMBER - DAMAGE : PATCH , REPAIR- REPLACE";
                    }

                    if (this.DB2N.Content.ToString() == "DB2N")
                    {
                        Border border = new Border();
                        border.Width = 60;
                        border.Height = 60;
                        border.Background = new SolidColorBrush(Color.FromArgb(255, (byte)_random.Next(255), (byte)_random.Next(255), (byte)_random.Next(255)));
                        DB2N.Content = border;
                        //TR2N.Content= "PANEL, PATCH,";
                        //output.Text = "DOOR PANEL - DAMAGE : DENT , REPAIR- STRAIGHTEN";
                    }
                }
            }

          //  MessageBox.Show(containerName);


            //foreach (var it in lst_westimdt)
            //{
            //    if (this.RB4N.Content.ToString() == it.WD_LOCATION)
            //    {
            //        //MessageBox.Show(it.WD_LINE);
            //        //MessageBox.Show(it.WD_LOCATION);
            //        //MessageBox.Show(this.RB4N.Content.ToString());
            //        Border border = new Border();
            //        border.Width = 60;
            //        border.Height = 60;
            //        border.Background = new SolidColorBrush(Color.FromArgb(255, (byte)_random.Next(255), (byte)_random.Next(255), (byte)_random.Next(255)));
            //        RB4N.Content = border;

            //    }

            //    if (this.UX3N.Content.ToString() == it.WD_LOCATION)
            //    {
            //        Border border = new Border();
            //        border.Width = 60;
            //        border.Height = 60;
            //        border.Background = new SolidColorBrush(Color.FromArgb(255, (byte)_random.Next(255), (byte)_random.Next(255), (byte)_random.Next(255)));
            //        UX3N.Content = border;
            //        //TR2N.Content= "PANEL, PATCH,";
            //        //output.Text = "UNDERSTRUCTURE PANEL- DAMAGE : SCRATCHES, REPAIR- WASHING & CLEANING";
            //    }

            //    if (this.RB4N.Content.ToString() == "RB4N")
            //    {

            //        //TR2N.Content= "PANEL, PATCH,";
            //        // output.Text = "PANEL - DAMAGE : DENT , REPAIR- STRAIGHTEN";
            //    }
            //    if (this.RH5N.Content.ToString() == "RH5N")
            //    {
            //        Border border = new Border();
            //        border.Width = 60;
            //        border.Height = 60;
            //        border.Background = new SolidColorBrush(Color.FromArgb(255, (byte)_random.Next(255), (byte)_random.Next(255), (byte)_random.Next(255)));
            //        RH5N.Content = border;
            //        //TR2N.Content= "PANEL, PATCH,";
            //        //output.Text = "CROSS MEMBER - DAMAGE : PATCH , REPAIR- REPLACE";
            //    }

            //    if (this.DB2N.Content.ToString() == "DB2N")
            //    {
            //        Border border = new Border();
            //        border.Width = 60;
            //        border.Height = 60;
            //        border.Background = new SolidColorBrush(Color.FromArgb(255, (byte)_random.Next(255), (byte)_random.Next(255), (byte)_random.Next(255)));
            //        DB2N.Content = border;
            //        //TR2N.Content= "PANEL, PATCH,";
            //        //output.Text = "DOOR PANEL - DAMAGE : DENT , REPAIR- STRAIGHTEN";
            //    }
            //}
            
        }

        void ClearContent()
        {
            this.RB1N.Content = "RB1N";
            this.UX1N.Content = "UX1N";
            this.RH1N.Content = "RH1N";
            this.DB4N.Content = "DB4N";
            this.D4.Content = "D4";
            this.RG1N.Content = "RG1N";
            this.RG2N.Content = "RG2N";
            this.RG3N.Content = "RG3N";
            this.RG4N.Content = "RG4N";
            this.RG5N.Content = "DB4N";
            this.F1G.Content = "F1G";
            this.DB4N.Content = "DB4N";
            this.RB1N.Content = "RB1N";
            this.RB2N.Content = "RB2N";
            this.RB3N.Content = "RB3N";
            this.RB4N.Content = "RB4N";
            this.RB5N.Content = "RB5N";
            this.FB1N.Content = "FB1N";
            this.FT1N.Content = "FT1N";
            this.DT4N.Content = "DT4N";
            this.RT1N.Content = "RT1N";
            this.RT2N.Content = "RT2N";
            this.RT3N.Content = "RT3N";
            this.RT4N.Content = "RT4N";
            this.RT5N.Content = "RT5N";
            this.D4H.Content = "D4H";
            this.RH1N.Content = "RH1N";
            this.RH2N.Content = "RH2N";
            this.RH3N.Content = "RH3N";
            this.RH4N.Content = "RH4N";
            this.RH5N.Content = "RH5N";
            this.F1H.Content = "F1H";
            this.TR1N.Content = "TR1N";
            this.TR2N.Content = "TR2N";
            this.TR3N.Content = "TR3N";
            this.TR4N.Content = "TR4N";
            this.TR5N.Content = "TR5N";
            this.TL1N.Content = "TL1N";
            this.TL2N.Content = "TL2N";
            this.TL3N.Content = "TL3N";
            this.TL4N.Content = "TL4N";
            this.TL5N.Content = "TL5N";
            this.D4D.Content = "D4D";
            this.DH3N.Content = "DH3N";
            this.DH2N.Content = "DH2N";
            this.D1.Content = "D1";
            this.LH1N.Content = "LH1N";
            this.LH2N.Content = "LH2N";
            this.LH3N.Content = "LH3N";
            this.LH4N.Content = "LH4N";
            this.LH5N.Content = "LH5N";
            this.F4H.Content = "F4H";
            this.FH3N.Content = "FH3N";
            this.FH2N.Content = "FH2N";
            this.F1TN.Content = "F1TN";
            this.DT3N.Content = "DT3N";
            this.DT2N.Content = "DT2N";
            this.DT1N.Content = "DT1N";
            this.LT1N.Content = "LT1N";
            this.LT2N.Content = "LT2N";
            this.LT3N.Content = "LT3N";
            this.LT4N.Content = "LT4N";
            this.LT5N.Content = "LT5N";
            this.FT4N.Content = "FT4N";
            this.FT3N.Content = "FT3N";
            this.FT2N.Content = "FT2N";
            this.FT1NF.Content = "FT1N";
            this.DB4ND.Content = "DB4N";
            this.DB3N.Content = "DB3N";
            this.DB2N.Content = "DB2N";
            this.DB1N.Content = "DB1N";
            this.LB1N.Content = "LB1N";
            this.LB2N.Content = "LB2N";
            this.LB3N.Content = "LB3N";
            this.LB4N.Content = "LB4N";
            this.LB5N.Content = "LB5N";
            this.FB3N.Content = "FB3N";
            this.FB2N.Content = "FB2N";
            this.FB1NF.Content = "FB1N";
            this.FB4N.Content = "FB4N";
            this.D4DG.Content = "D4DG";
            this.DG3N.Content = "DG3N";
            this.DG2N.Content = "DG2N";
            this.D1G.Content = "D1G";
            this.LG1N.Content = "LG1N";
            this.LG2N.Content = "LG2N";
            this.LG3N.Content = "LG3N";
            this.LG4N.Content = "LG4N";
            this.LG5N.Content = "LG5N";
            this.F4G.Content = "F4G";
            this.FG3N.Content = "FG3N";
            this.FG2N.Content = "FG2N";
            this.F1GN.Content = "F1GN";
            this.BL1N.Content = "BL1N";
            this.BL2N.Content = "BL2N";
            this.BL3N.Content = "BL3N";
            this.BL4N.Content = "BL4N";
            this.BL5N.Content = "BL5N";
            this.BR1N.Content = "BR1N";
            this.BR2N.Content = "BR2N";
            this.BR3N.Content = "BR3N";
            this.BRL4N.Content = "BR4N";
            this.BR5N.Content = "BR5N";
            this.UX1N.Content = "UX1N";
            this.UX2N.Content = "UX2N";
            this.UX3N.Content = "UX3N";
            this.UX4N.Content = "UX4N";
            this.UX5N.Content = "UX5N";
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        void point_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            // Show a popup with data about that point
            CustomerPushpin pin = sender as CustomerPushpin;
            if (pin != null)
            {
                MapLayer.SetPosition(ContentPopup, pin.Location);
                MapLayer.SetPositionOffset(ContentPopup, new Point(0, -60));



                string contentString = pin.CustomerId.ToString() + "   " + pin.CustomerName.ToString();
                //Remove tags from the string
                Regex regex = new Regex("<(.|\n)*?>");
                contentString = regex.Replace(contentString, string.Empty);
                ContentPopupText.Text = contentString;
                ContentPopup.Visibility = Visibility.Visible;

                ReLoad(pin.CustomerName.ToString());


            }
        }

        void point_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            //Hide the popup
            CustomerPushpin point = sender as CustomerPushpin;
            ContentPopup.Visibility = Visibility.Collapsed;
        }

        private void ContentPopup_MouseEnter(object sender, MouseEventArgs e)
        {
            //Show the popup
            (sender as Canvas).Visibility = Visibility.Visible;
            Canvas.SetZIndex((sender as Canvas), 10);
        }

        private void ContentPopup_MouseLeave(object sender, MouseEventArgs e)
        {
            ////Show the popup
            (sender as Canvas).Visibility = Visibility.Collapsed;
        }

        private void OnButtonTransformInteractionControlClick(object sender, EventArgs e)
        {
            //output.Text = "Button container clicked!";
            this.TR2N.Content = "TR2N";

            if (this.TR2N.Content.ToString() == "TR2N")
            {
                Border border = new Border();
                border.Width = 60;
                border.Height = 60;
                border.Background = new SolidColorBrush(Color.FromArgb(255, (byte)_random.Next(255), (byte)_random.Next(255), (byte)_random.Next(255)));
                TR2N.Content = border;
               // output.Text = "PANEL - DAMAGE : PATCH , REPAIR- REPLACE";
            }
        }

        private void OnBorderTransformInteractionControlClick(object sender, EventArgs e)
        {
            //output.Text = "Border container clicked!";

            //if (this.RB4N.Content.ToString() == "RB4N")
            //{
            //    Border border = new Border();
            //    border.Width = 60;
            //    border.Height = 60;
            //    border.Background = new SolidColorBrush(Color.FromArgb(255, (byte)_random.Next(255), (byte)_random.Next(255), (byte)_random.Next(255)));
            //    RB4N.Content = border;
            //    //TR2N.Content= "PANEL, PATCH,";
            //    output.Text = "PANEL - DAMAGE : DENT , REPAIR- STRAIGHTEN";
            //}
            //if (this.UX3N.Content.ToString() == "UX3N")
            //{
            //    Border border = new Border();
            //    border.Width = 60;
            //    border.Height = 60;
            //    border.Background = new SolidColorBrush(Color.FromArgb(255, (byte)_random.Next(255), (byte)_random.Next(255), (byte)_random.Next(255)));
            //    UX3N.Content = border;
            //    //TR2N.Content= "PANEL, PATCH,";
            //    output.Text = "UNDERSTRUCTURE PANEL- DAMAGE : SCRATCHES, REPAIR- WASHING & CLEANING";
            //}
        }

        private void OnButtonTransformInteractionControlClick_Test2(object sender, EventArgs e)
        {
            //output.Text = "Test 2- Button container clicked!";

            //if (this.RH5N.Content.ToString() == "RH5N")
            //{
            //    Border border = new Border();
            //    border.Width = 60;
            //    border.Height = 60;
            //    border.Background = new SolidColorBrush(Color.FromArgb(255, (byte)_random.Next(255), (byte)_random.Next(255), (byte)_random.Next(255)));
            //    RH5N.Content = border;
            //    //TR2N.Content= "PANEL, PATCH,";
            //    output.Text = "CROSS MEMBER - DAMAGE : PATCH , REPAIR- REPLACE";
            //}

            //if (this.DB2N.Content.ToString() == "DB2N")
            //{
            //    Border border = new Border();
            //    border.Width = 60;
            //    border.Height = 60;
            //    border.Background = new SolidColorBrush(Color.FromArgb(255, (byte)_random.Next(255), (byte)_random.Next(255), (byte)_random.Next(255)));
            //    DB2N.Content = border;
            //    //TR2N.Content= "PANEL, PATCH,";
            //    output.Text = "DOOR PANEL - DAMAGE : DENT , REPAIR- STRAIGHTEN";
            //}
        }

        private void OnButtonTransformInteractionControlClick_Text(object sender, EventArgs e)
        {
            //if (this.RH5N.Content.ToString() == "RH5N")
            //{
            //    Border border = new Border();
            //    border.Width = 60;
            //    border.Height = 60;
            //    border.Background = new SolidColorBrush(Color.FromArgb(255, (byte)_random.Next(255), (byte)_random.Next(255), (byte)_random.Next(255)));
            //    RH5N.Content = border;
            //    //TR2N.Content= "PANEL, PATCH,";
            //    output.Text = "CROSS MEMBER - DAMAGE : PATCH , REPAIR- REPLACE";
            //}

            //if (this.DB2N.Content.ToString() == "DB2N")
            //{
            //    Border border = new Border();
            //    border.Width = 60;
            //    border.Height = 60;
            //    border.Background = new SolidColorBrush(Color.FromArgb(255, (byte)_random.Next(255), (byte)_random.Next(255), (byte)_random.Next(255)));
            //    DB2N.Content = border;
            //    //TR2N.Content= "PANEL, PATCH,";
            //    output.Text = "DOOR PANEL - DAMAGE : DENT , REPAIR- STRAIGHTEN";
            //}
        }

        private void OnAddButtonClick(object sender, RoutedEventArgs e)
        {
            //TransformInteraction.TransformInteractionControl transformControl = new TransformInteraction.TransformInteractionControl();
            //transformControl.HorizontalAlignment = HorizontalAlignment.Center;
            //transformControl.VerticalAlignment = VerticalAlignment.Center;
            //Border border = new Border();
            //border.Width = 50;
            //border.Height = 50;
            //border.Background = new SolidColorBrush(Color.FromArgb(255, (byte)_random.Next(255), (byte)_random.Next(255), (byte)_random.Next(255)));
            //transformControl.Content = border;
            //LayoutRoot.Children.Add(transformControl);
        }

        private void MyMap_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void RG1N_MouseEnter(object sender, MouseEventArgs e)
        {
            //this.TR2N.Content = "TR2N";

            //if (this.TR2N.Content.ToString() == "TR2N")
            //{
            //    Border border = new Border();
            //    border.Width = 60;
            //    border.Height = 60;
            //    border.Background = new SolidColorBrush(Color.FromArgb(255, (byte)_random.Next(255), (byte)_random.Next(255), (byte)_random.Next(255)));
            //    TR2N.Content = border;
                // output.Text = "PANEL - DAMAGE : PATCH , REPAIR- REPLACE";

            AssignDamageReport("RG1N");
            
        }

        private void D4_MouseEnter(object sender, MouseEventArgs e)
        {

            AssignDamageReport("D4");

        }

        private void RG2N_MouseEnter(object sender, MouseEventArgs e)
        {

            AssignDamageReport("RG3N");

        }
        private void RG3N_MouseEnter(object sender, MouseEventArgs e)
        {

            AssignDamageReport("RG3N");

        }
        private void RG4N_MouseEnter(object sender, MouseEventArgs e)
        {

            AssignDamageReport("RG4N");

        }
        private void RG5N_MouseEnter(object sender, MouseEventArgs e)
        {

            AssignDamageReport("RG5N");

        }
        void AssignDamageReport(string loc)
        {

            Location_text.Text = loc;
            damage_text.Text = "DT,DENT";
            Repair_text.Text = "RP,REPLACE";
            Costtype_text.Text = "HIGH";
            PosRpr_text.Text = "ST(straighten),PT(patch)";
            PosAdjSide_text.Text = "RB1N,RB2N,RG2N,DB,D4";
            DamageImpact_text.Text = "High";
            duplctrpr_txt.Text = "nil";

            // TARIFF -REPORTED
            RepMH_txt.Text = "2";
            RepMC_txt.Text = "45.00";
            RepLR_txt.Text = "30";
            // TARIFF -EXPECTED
            ExpMH_txt.Text = "1.5";
            ExpMC_txt.Text = "45.00";
            ExpLR_txt.Text = "30";
        }
          
    }
    public class CustomerPushpin : Pushpin
    {
        public string CustomerName { get; set; }
        public string CustomerId { get; set; }
        public string CustomerAddress { get; set; }
        public CustomerPushpin(Color Bg)
        {
            this.Name = Guid.NewGuid().ToString();
            SolidColorBrush scb = new SolidColorBrush(Bg);
            this.Background = scb;
        }
    }

    public class Customer
    {
        public string CustomerName { get; set; }
        public string CustomerId { get; set; }

    }

    
}
